<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<fsButton ref="button" plain size="small" :buttons="buttons" @clickHandler="buttonHandler"></fsButton>
			</div>
			<div class="right-panel">
				<ex-search ref="search" :searches="searches" @searchOk="searchHandler" default-code="code" placeholder="请输入资产编码" :fixedParam="{assetStatusId:'idle'}"></ex-search>
			</div>
		</el-header>
		<el-main class="nopadding">

			<ex-table id="checkTaskTable" ref="table" :columns="columns" :tablename="'闲置资产'" :url="this.$API.asset.asset.list.url" :refs="this.$refs" search="search" @columnClick="columnClickHandler"></ex-table>
		</el-main>
	</el-container>
	<data-card ref="dataCard"></data-card>
</template>

<script>
import ExTable from "@/components/exTable/index.vue";
import ExSearch from "@/components/exSearch/index.vue";
import ExTreeNavigation from "@/components/exSearchTree/index.vue";
import ExSearchTree from "@/components/exSearchTree/index.vue";
import scSelectFilter from "@/components/scSelectFilter/index.vue";
import tool from "@/utils/tool";
import DataCard from "@/views/asset/card/card.vue";
import BaseTemplate from "@/utils/baseTemplate";
export default {
	name: '闲置资产',
	components: {
		DataCard,
		scSelectFilter,
		ExSearchTree,
		ExTreeNavigation,
		ExSearch,
		ExTable,
	},
	data() {
		return {
			dialog: {
				save: false,
				permission: false,
			},
			apiObj: [],
			buttons: [
				{name: "导出", icon: "el-icon-download", click: "export", type: "info", permission: "export"},
			],
			searches: [
				{type: "input", name: "资产编码", code: "code", placeholder: "请输入资产编码", maxlength: 30, showLimit: true},
				{type: "input", name: "资产名称", code: "name", placeholder: "请输入资产名称"},
				{type: "input", name: "财务编码", code: "financialCode", placeholder: "请输入财务编码"},
				{type: "daterange", name: "闲置日期", code: "zcxzDateStart,zcxzDateEnd", placeholder: "请选择闲置日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
				{type: "tree-select", name: "资产类别", code: "assetCategoryIds", placeholder: "请选择资产类别", dictCode:'FamsAssetCategory',multiple:true,checkStrictly:true},
				// {type: "cascade", name: "制定部门", code: "createOrg", placeholder: "请选择制定部门", dictCode:'SysOrganization'},
				{type: "input", name: "规格型号", code: "model", placeholder: "请输入规格型号"},
				{type: "input", name: "资产品牌", code: "brand", placeholder: "请输入资产品牌"},
				{type: "daterange", name: "入库日期", code: "createTimeStart,createTimeEnd", placeholder: "请选择入库日期", formatter:"YYYY-MM-dd",valueFormat:"YYYYMMDD",range:365},
			],
			columns: [
				{code: "assetStatusId", name: "资产状态", width:"85",formatter:"DICT",key: "ASSET_STATUS", sortable: true},
				{code: "code", name: "资产编码", width:"135",click:"show1"},
				{code: "financialCode", name: "财务编码", width:"170"},
				{code: "name", name: "资产名称", width:"200"},
				{code: "other.zcxzDate", name: "闲置日期", width:"110",formatter: "DATE", sortable: true},
				{code: "mainCategoryCode", name: "资产大类",width:"110", formatter:"DICT",key: "FamsAssetCategory", sortable: true},
				{code: "assetCategoryId", name: "资产小类",width:"220", formatter:"DICT",key: "FamsAssetCategory", sortable: true},
				{code: "storePlaceId", name: "资产位置",width: "120", formatter:"DICT",key: "FamsPosition"},
				{code: "brand", name: "品牌", width:""},
				{code: "model", name: "规格型号", width:""},
				{code: "serialCode", name: "资产序列号", width:"150"},
				{code: "assetCount", name: "数量", width:"80",summary:true},
				{code: "originalValue", name: "资产原值", width:"150",summary:true},
				{code: "netValue", name: "资产净值", width:"150",summary:true},
				{code: "usingMenId", name: "使用人", width:"110",formatter: "DICT",key: "SysUser"},
				{code: "usingDepartmentId", name: "使用部门", width:"150",formatter: "DICT",key: "SysOrganization"},
				{code: "dutyDepartmentId", name: "管理部门", width:"150",formatter: "DICT",key: "SysOrganization"},
				{code: "createTime", name: "入库日期", width:"110",formatter: "DATE", sortable: true},
				{code: "other.scrapDate", name: "报废日期", width:"110",formatter: "DATE", sortable: true},
			],
			parentLevelCode:"",
			assetIds:[],
			loading: false,
		}
	},
	created() {
	},
	mounted() {
	},
	beforeMount() {

	},
	methods: {
		buttonHandler(index, name) {
			this.$options.methods[name](this, index);
		},
		async searchTreeHandler(data) {
			let queryParams = {pathCode:data.levelCode}
			this.parentLevelCode= data.levelCode;
			await this.$refs.table.refresh(queryParams);
		},

		async searchHandler() {
			let queryParams = {pathCode: this.parentLevelCode}
			await this.$refs.table.refresh(queryParams);
		},
		columnClickHandler(name,data){
			this.$options.methods[name](this, data);
		},
		//查看
		async show1(_this, row) {
			let assetCategory = await _this.$cache.data.loadAssetCategory(row.assetCategoryId);
			try {
				_this.loading = true;
				let entity = {cardId: assetCategory.assetCardId, _editFlag: false}
				_this.$nextTick(() => {
					_this.cardPreview = false;
					_this.$refs.dataCard.open(Object.assign(entity, row));
				});
			} finally {
				_this.loading = false;
			}
		},
		//导出
		async export(_this,index) {
      let attachParams = {};
      attachParams.exportType = "idleAsset";
      let exportApi = _this.$API.asset.asset.export;
      let exTableRef = _this.$refs.table;
      let exportBtnRef = _this.$refs.button;
      let exportBtnIndex = index;
      await BaseTemplate.export(_this, exportApi, attachParams, exportBtnRef, exportBtnIndex, exTableRef);
		},
	}
}

</script>
<style scoped>

</style>
